package com.jasonkurtzman.adv;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import com.jasonkurtzman.adv.Entity.Player;
import com.jasonkurtzman.adv.Level.Level;
import com.jasonkurtzman.adv.Tile.Tile;

public class GamePanel extends JPanel{
	private static final long serialVersionUID = 1L;
	
	public static final int XSIZE = 800;
	public static final int YSIZE = 600;
	
	public static Level level = new Level();
	Player player = new Player(40, 40, 100);
	
	public static InputHandler input = new InputHandler();
	
	public GamePanel()
	{
		this.setSize(XSIZE, YSIZE);
		this.setBackground(Color.WHITE);
		//this.addKeyListener(input);
		level.genLevel();
	}
	
	public void tick()
	{
		while(true)
		{
			if(input.forward) player.y -= 2;
			if(input.backward) player.y += 2;
			if(input.left) player.x -= 2;
			if(input.right) player.x += 2;
			
			if((player.y + 10) % 40 == 0 && (player.x + 10) % 40 == 0)
			{
				if(level.worldTiles[player.x + 10][(player.y + 10) + Tile.TILE_SIZE].getTileID() == 2) System.out.println("Stone");
			}
			
			repaint();
			
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		//System.out.println("Array: "  + level.worldTiles.length + " || " + level.worldTiles[0].length);
		level.render(g);
		player.render(g);
	}
}
